package hn.cch.version.lts11.feature;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

public class VarHandleTest {

    public static void main(String[] args) {

        VarTarget varTarget = new VarTarget();
        varTarget.setVarString("hello world");

        try {
            VarHandle varHandle = MethodHandles.lookup().findVarHandle(VarTarget.class, "varString", String.class);
            // Object object = varHandle.get(varTarget);
            Object object = varHandle.getAcquire(varTarget);
            // Object object = varHandle.getVolatile(varTarget);

            // if (object instanceof String){
            //     System.out.println(object);
            // }

        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }

    }


}
